import { Controller, Get, Put, Body, UseGuards, Query } from '@nestjs/common';
import { AddressService } from './address.service';
import { Address } from '../entities/address.entity';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('address')
@UseGuards(JwtAuthGuard)
export class AddressController {
  constructor(private readonly addressService: AddressService) {}

  @Get()
  async getAddress(@Query('phone') phone: string): Promise<Address> {
    return this.addressService.getAddress(phone);
  }

  @Put()
  async updateAddress(
    @Query('phone') phone: string,
    @Body() addressData: Partial<Address>,
  ): Promise<Address> {
    return this.addressService.updateAddress(phone, addressData);
  }
}
